///////////////////
/// mkIV - Game ///
///////////////////

// Game includes
#include "../../Game/Independent/mkGameEngine.h"

namespace mk
{
namespace Game
{

Errno GameEngine::Create( GameEngine*& gameEngine )
{
    Errno errResult = Errno_Success;

    // Create a new GameEngine.
    GameEngine* engine = mkNew GameEngine();
    if( !engine )
    {
        return ErrnoMessage( Errno_NoMemory, "Failed to allocate memory for GameEngine." );
    }

    errResult = engine->Initialise();
    if( mkErrnoFailure( errResult ) )
    {
        mkDelete engine;
        return errResult;
    }

    // Assign the GameEngine.
    gameEngine = engine;
    return Errno_Success;
}

GameEngine::~GameEngine( )
{
    Shutdown();
}

Errno GameEngine::EnterMainLoop( )
{
    return Errno_Success;
}

Errno GameEngine::ExitMainLoop ( )
{
    return Errno_Success;
}

Errno GameEngine::SingleTick   ( TickInfo const& info )
{
    return Errno_Success;
}

GameEngine::GameEngine( )
{

}

Errno GameEngine::Initialise( )
{
    Errno errResult = Errno_Success;

    if( mkErrnoFailure( errResult = InitialiseCoreLib() ) )
    {
        return errResult;
    }

    if( mkErrnoFailure( errResult = InitialiseEngineLib() ) )
    {
        return errResult;
    }

    return errResult;
}

Errno GameEngine::InitialiseCoreLib( )
{
    return Errno_Success;
}

Errno GameEngine::InitialiseEngineLib( )
{
    return Errno_Success;
}

Errno GameEngine::Shutdown( )
{
    Errno errResult = Errno_Success;

    if( mkErrnoFailure( errResult = ShutdownCoreLib() ) )
    {
        return errResult;
    }

    if( mkErrnoFailure( errResult = ShutdownEngineLib() ) )
    {
        return errResult;
    }

    return errResult;
}

Errno GameEngine::ShutdownCoreLib( )
{
    return Errno_Success;
}

Errno GameEngine::ShutdownEngineLib( )
{
    return Errno_Success;
}

} // namespace Game
} // namespace mk

